package com.bootdo.order.controller;

import com.bootdo.common.utils.R;
import com.bootdo.merchant.domain.AgentDO;
import com.bootdo.merchant.domain.MerchantDO;
import com.bootdo.order.service.OrderMercService;
import com.bootdo.order.service.OrderPayeeService;
import com.bootdo.order.service.ProfitService;
import com.bootdo.payee.domain.PayeeAgentDO;
import com.bootdo.payee.domain.PayeeDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.bootdo.common.utils.ShiroUtils.getUser;

/**
 * @Desc 统计
 * @date 2019/12/25
 *
 */
@Controller
@RequestMapping("/orders/profit")
public class ProfitController {

    private final String PREFIX = "orders/profit";
    @Autowired
    private ProfitService profitService;
    @Autowired
    private OrderPayeeService orderPayeeService;
    @Autowired
    private OrderMercService orderMercService;

    @GetMapping()
    @RequiresPermissions("orders:profit:profit")
    String order(Model model) {
        model.addAttribute("agentList", orderMercService.findAgent());
        model.addAttribute("merchantList", orderMercService.findMerchant(null));
        model.addAttribute("roleId", getUser().getRoleIds().get(0));
        return PREFIX + "/list";
    }

    @ResponseBody
    @PostMapping("/findPayeeAgent")
    @RequiresPermissions("orders:profit:profit")
    public R findPayeeAgent(Long userId){
        List<PayeeAgentDO> list = orderPayeeService.findAgent();
        return R.ok(list);
    }

    @ResponseBody
    @PostMapping("/findPayee")
    @RequiresPermissions("orders:profit:profit")
    public R findPayee(Long userId){
        List<PayeeDO> list = orderPayeeService.findPayee(userId);
        return R.ok(list);
    }

    @ResponseBody
    @PostMapping("/findMerchantAgent")
    @RequiresPermissions("orders:profit:profit")
    public R findMerchantAgent(Long userId){
        List<AgentDO> list = orderMercService.findAgent();
        return R.ok(list);
    }

    @ResponseBody
    @PostMapping("/findMerchant")
    @RequiresPermissions("orders:profit:profit")
    public R findMerchant(Long userId){
        List<MerchantDO> list = orderMercService.findMerchant(userId);
        return R.ok(list);
    }

    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions("orders:profit:profit")
    R list(@RequestParam Map<String, Object> params){
        return R.ok(profitService.list(params));
    }

    @ResponseBody
    @PostMapping("/queryP")
    R queryP(@RequestParam Map<String, Object> params){ return  R.ok(profitService.queryP(params)); }

    @ResponseBody
    @PostMapping("/queryM")
    R queryM(@RequestParam Map<String, Object> params){ return  R.ok(profitService.queryM(params)); }

//    @PostMapping("/queryMerc")
//    public R queryProfitByMerc(@RequestParam Map<String, Object> params){
//        //获取统计数据
//        Map<String, String> map = profitService.queryProfitByMerc(params);
//        return R.ok(map);
//    }
//
//    @PostMapping("/queryPayee")
//    public R queryProfitByPayee(@RequestParam Map<String, Object> params){
//        //获取统计数据
//        Map<String, String> map = profitService.queryProfitByPayee(params);
//        return R.ok(map);
//    }
}
